package cn.uexpo.lhz.controller.admin;

import cn.uexpo.lhz.biz.*;
import cn.uexpo.lhz.common.oldBase.BaseController;
import cn.uexpo.lhz.common.oldUtils.PageRequest;
import cn.uexpo.lhz.common.oldUtils.PageResult;
import cn.uexpo.lhz.plus.PageUtils;
import cn.uexpo.lhz.plus.R;
import cn.uexpo.lhz.core.http.HttpResult;
import cn.uexpo.lhz.domain.*;
import cn.uexpo.lhz.plus.PageUtils;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 多对多 项目——摄像头
 * 统计设备配置
 *
 * @author
 * @since
 */
@RestController
@RequestMapping("/cert/many")
public class ManyController extends BaseController<Many> {
    @Autowired
    private ManyBiz manyBiz;
    @Autowired
    private EventBiz eventBiz;
    @Autowired
    private EquipmentBiz equipmentBiz;
    @Autowired
    private CameranotiyBiz cameranotiyBiz;
    @Autowired
    private CamerastatusBiz camerastatusBiz;
    @Autowired
    private TotalSaveBiz totalSaveBiz;


    @Autowired
    private EquipmentService equipmentService;


    /**
     * vue项目 多对多数人数设备表格展示
     *
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/findPage")
    public HttpResult findPage(@RequestParam Map<String, Object> params) {
        PageRequest pageRequest = new PageRequest();
        PageResult result = null;
        String page = (String)params.get("page");
        String limit = (String)params.get("limit");
        String name = (String)params.get("name");
        if (!"".equals(page) && !"".equals(limit)) {
            pageRequest.setPage(Integer.parseInt(page));
            pageRequest.setLimit(Integer.parseInt(limit));
        }
        Many2Vo vo = new Many2Vo();
        vo.setName(name);
        if (!"".equals(name) && null != name) {
            result = manyBiz.findPage1(pageRequest, vo);
        } else {
            result = findPage1(pageRequest);
        }
        return HttpResult.ok(result);
    }

    private PageResult findPage1(PageRequest pageRequest) {
        // ManyExample example = new ManyExample();
        // PageResult result=manyBiz.findPage(pageRequest,example);
        // 三表关联数据
        PageResult result = manyBiz.findPageMany(pageRequest);
        return result;
    }


    /**
     * 多对多数据输出 大屏页面
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/dataAll", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Map<String, Object> dataAll() throws Exception {
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
        String code = "500";
        String msg = "失败";
        List<JSONObject> list = new ArrayList<JSONObject>();
        Map<String, Object> map = new HashMap<String, Object>();
        int no = 0;
        int comeTotal2 = 0;
        int outTotal2 = 0;
        int comeTotal3 = 0;
        int outTotal3 = 0;
        int comeTotal = 0;
        int outTotal = 0;
        String cName = null;

        List<JSONObject> list1 = new ArrayList<JSONObject>();
        List<JSONObject> list2 = new ArrayList<JSONObject>();
        String name = request.getParameter("name");// 项目名称
        String cameraName = request.getParameter("cameraName");//摄像头名称
        //number   可以和摄像头数据合并
        if (null != name && !"".equals(name)) {
            // 根据项目名找到项目   max(id)
            CameranotiyExample cameranotiyExample2 = new CameranotiyExample();
            CameranotiyExample.Criteria cameranotiyCiteria2 = cameranotiyExample2.createCriteria();
            cameranotiyCiteria2.andEventNameLike(name);
//				if(null != cameraName && !"".equals(cameraName)) {
//					cameranotiyCiteria2.andExtstr1EqualTo(cameraName);
//				}
            List<Integer> lists = cameranotiyBiz.selectMaxByAll(cameranotiyExample2);
            int comeTotalNumCamera = 0;
            int outTotalNumCamera = 0;
            for (int l : lists) {

                Cameranotiy cameranotiy = cameranotiyBiz.selectByNumber(l);
                cName = cameranotiy.getExtstr1();
                String equipmentNumber = cameranotiy.getExtstr2();
                comeTotal = cameranotiy.getCometotal();// 进人数
                outTotal = cameranotiy.getOuttotal();// 出人数
                comeTotalNumCamera = comeTotalNumCamera + comeTotal;
                outTotalNumCamera = outTotalNumCamera + outTotal;
                JSONObject obj1 = new JSONObject();
                JSONObject obj2 = new JSONObject();

                obj1.put("value", comeTotal);
                obj1.put("name", cName);
                obj2.put("value", outTotal);
                obj2.put("name", cName);
                list1.add(obj1);
                list2.add(obj2);

            }
            //时间点 时间段
            for (int i = 22; i >= 6; i--) {
                JSONObject object = new JSONObject();
                Date date = new Date();
                Calendar cal = Calendar.getInstance();
                int hour = cal.get(Calendar.HOUR_OF_DAY);
                String t = f.format(date);
                if (i > hour) {
                    continue;
                } else if (null != cameraName && !"".equals(cameraName)) {
                    TotalSaveExample totalSaveExample = new TotalSaveExample();
                    TotalSaveExample.Criteria totalCriteria = totalSaveExample.createCriteria();
                    totalCriteria.andExstr1EqualTo(t);
                    totalCriteria.andTimepointEqualTo(i + "");
                    totalCriteria.andExstr2EqualTo(cameraName);
                    totalCriteria.andExstr3EqualTo(name);
                    List<TotalSave> totalSaves = totalSaveBiz.selectByExample(totalSaveExample);
                    int comeTotalNum = 0;
                    int outTotalNum = 0;
                    int comeTotalNum2 = 0;
                    int outTotalNum2 = 0;
                    int comNum = 0;
                    int outNum = 0;
                    if (null != totalSaves && totalSaves.size() > 0) {
                        TotalSave totalSave = totalSaves.get(totalSaves.size() - 1);

                        int cTotalNum = totalSave.getCometotalnum();
                        int oTotalNum = totalSave.getOuttotalnum();
                        int onTotalPointNum = totalSave.getOntotalpointnum();
                        object.put("timePoint", i);
                        object.put("onTotalPointNum", onTotalPointNum);
                        object.put("time", i - 1 + "-" + i);
                        object.put("comeTotalNum", cTotalNum);
                        object.put("outTotalNum", oTotalNum);
                    } else {
                        CameranotiyExample cameranotiyExample3 = new CameranotiyExample();
                        CameranotiyExample.Criteria cameranotiyCiteria3 = cameranotiyExample3.createCriteria();
                        cameranotiyCiteria3.andEventNameLike(name);
                        cameranotiyCiteria3.andExtstr1EqualTo(cameraName);
                        cameranotiyCiteria3.andExtstr3EqualTo(t);
                        cameranotiyCiteria3.andExtstr4EqualTo(i - 1 + "");
                        List<Integer> lists2 = cameranotiyBiz.selectMaxByAll(cameranotiyExample3);
                        CameranotiyExample cameranotiyExample = new CameranotiyExample();
                        CameranotiyExample.Criteria cameranotiyCiteria = cameranotiyExample.createCriteria();
                        cameranotiyCiteria.andEventNameLike(name);
                        cameranotiyCiteria.andExtstr1EqualTo(cameraName);
                        cameranotiyCiteria.andExtstr3EqualTo(t);
                        cameranotiyCiteria.andExtstr4EqualTo(i - 2 + "");
                        List<Integer> lists3 = cameranotiyBiz.selectMaxByAll(cameranotiyExample);
                        if (null != lists2 && lists2.size() > 0) {
                            if (null != lists3 && lists3.size() > 0) {
                                for (int l : lists2) {
                                    Cameranotiy cameranotiy = cameranotiyBiz.selectByNumber(l);
                                    String camera2 = cameranotiy.getExtstr1();
                                    comeTotal2 = cameranotiy.getCometotal();// 进人数
                                    outTotal2 = cameranotiy.getOuttotal();// 出人数
                                    Boolean flag = false;
                                    for (int l3 : lists3) {
                                        Cameranotiy cameranotiy3 = cameranotiyBiz.selectByNumber(l3);
                                        String camera3 = cameranotiy3.getExtstr1();
                                        comeTotal3 = cameranotiy3.getCometotal();// 进人数
                                        outTotal3 = cameranotiy3.getOuttotal();// 出人数
                                        if (camera3.equals(camera2)) {
                                            flag = true;
                                            break;
                                        }
                                    }
                                    if (flag) {
                                        comNum = comNum + (comeTotal2 - comeTotal3);
                                        outNum = outNum + (outTotal2 - outTotal3);
                                    } else {
                                        comNum = comNum + comeTotal2;
                                        outNum = outNum + outTotal2;
                                    }
                                }
                            } else {
                                for (int l : lists2) {
                                    Cameranotiy cameranotiy = cameranotiyBiz.selectByNumber(l);
                                    String camera2 = cameranotiy.getExtstr1();
                                    comeTotal2 = cameranotiy.getCometotal();// 进人数
                                    outTotal2 = cameranotiy.getOuttotal();// 出人数
                                    comNum = comNum + comeTotal2;
                                    outNum = outNum + outTotal2;
                                }
                            }
                        } else {
                            comNum = 0;
                            outNum = 0;
                        }
                        TotalSave totalSave = new TotalSave();
                        totalSave.setCometotalnum(comNum);
                        totalSave.setTimepoint(i + "");
                        totalSave.setTime(i - 1 + "-" + i);
                        totalSave.setOuttotalnum(outNum);
                        totalSave.setOntotalpointnum(comNum - outNum);
                        totalSave.setExstr1(t);
                        totalSave.setExstr2(cameraName);
                        totalSave.setExstr3(name);
                        totalSaveBiz.insert(totalSave);
                        object.put("timePoint", i);
                        object.put("onTotalPointNum", comNum - outNum);
                        object.put("time", i - 1 + "-" + i);
                        object.put("comeTotalNum", comNum);
                        object.put("outTotalNum", outNum);
                    }
                } else {
                    TotalSaveExample totalSaveExample = new TotalSaveExample();
                    TotalSaveExample.Criteria totalCriteria = totalSaveExample.createCriteria();
                    totalCriteria.andExstr1EqualTo(t);
                    totalCriteria.andTimepointEqualTo(i + "");
                    totalCriteria.andExstr3EqualTo(name);
                    totalCriteria.andExstr2EqualTo("all");
                    List<TotalSave> totalSaves = totalSaveBiz.selectByExample(totalSaveExample);
                    int comeTotalNum = 0;
                    int outTotalNum = 0;
                    int comeTotalNum2 = 0;
                    int outTotalNum2 = 0;
                    int comNum = 0;
                    int outNum = 0;
                    if (null != totalSaves && totalSaves.size() > 0) {
                        TotalSave totalSave = totalSaves.get(totalSaves.size() - 1);
                        int cTotalNum = totalSave.getCometotalnum();
                        int oTotalNum = totalSave.getOuttotalnum();
                        int onTotalPointNum = totalSave.getOntotalpointnum();
                        object.put("timePoint", i);
                        object.put("onTotalPointNum", onTotalPointNum);
                        object.put("time", i - 1 + "-" + i);
                        object.put("comeTotalNum", cTotalNum);
                        object.put("outTotalNum", oTotalNum);
                    } else {
                        CameranotiyExample cameranotiyExample3 = new CameranotiyExample();
                        CameranotiyExample.Criteria cameranotiyCiteria3 = cameranotiyExample3.createCriteria();
                        cameranotiyCiteria3.andEventNameLike(name);
                        cameranotiyCiteria3.andExtstr3EqualTo(t);
                        cameranotiyCiteria3.andExtstr4EqualTo(i - 1 + "");
                        List<Integer> lists2 = cameranotiyBiz.selectMaxByAll(cameranotiyExample3);

                        CameranotiyExample cameranotiyExample = new CameranotiyExample();
                        CameranotiyExample.Criteria cameranotiyCiteria = cameranotiyExample.createCriteria();
                        cameranotiyCiteria.andEventNameLike(name);
                        cameranotiyCiteria.andExtstr3EqualTo(t);
                        cameranotiyCiteria.andExtstr4EqualTo(i - 2 + "");
                        List<Integer> lists3 = cameranotiyBiz.selectMaxByAll(cameranotiyExample);
                        if (null != lists2 && lists2.size() > 0) {
                            if (null != lists3 && lists3.size() > 0) {
                                for (int l : lists2) {
                                    Cameranotiy cameranotiy = cameranotiyBiz.selectByNumber(l);
                                    String camera2 = cameranotiy.getExtstr1();
                                    comeTotal2 = cameranotiy.getCometotal();// 进人数
                                    outTotal2 = cameranotiy.getOuttotal();// 出人数
                                    Boolean flag = false;
                                    for (int l3 : lists3) {
                                        Cameranotiy cameranotiy3 = cameranotiyBiz.selectByNumber(l3);
                                        String camera3 = cameranotiy3.getExtstr1();
                                        comeTotal3 = cameranotiy3.getCometotal();// 进人数
                                        outTotal3 = cameranotiy3.getOuttotal();// 出人数
                                        if (camera3.equals(camera2)) {
                                            flag = true;
                                            break;
                                        }
                                    }
                                    if (flag) {
                                        comNum = comNum + (comeTotal2 - comeTotal3);
                                        outNum = outNum + (outTotal2 - outTotal3);
                                    } else {
                                        comNum = comNum + comeTotal2;
                                        outNum = outNum + outTotal2;
                                    }
                                }
                            } else {
                                for (int l : lists2) {
                                    Cameranotiy cameranotiy = cameranotiyBiz.selectByNumber(l);
                                    String camera2 = cameranotiy.getExtstr1();
                                    comeTotal2 = cameranotiy.getCometotal();// 进人数
                                    outTotal2 = cameranotiy.getOuttotal();// 出人数
                                    comNum = comNum + comeTotal2;
                                    outNum = outNum + outTotal2;
                                }
                            }
                        } else {
                            comNum = 0;
                            outNum = 0;
                        }
                        TotalSave totalSave = new TotalSave();
                        totalSave.setCometotalnum(comNum);
                        totalSave.setTimepoint(i + "");
                        totalSave.setTime(i - 1 + "-" + i);
                        totalSave.setOuttotalnum(outNum);
                        totalSave.setOntotalpointnum(comNum - outNum);
                        totalSave.setExstr1(t);
                        totalSave.setExstr2("all");
                        totalSave.setExstr3(name);
                        totalSaveBiz.insert(totalSave);
                        object.put("timePoint", i);
                        object.put("onTotalPointNum", comNum - outNum);
                        object.put("time", i - 1 + "-" + i);
                        object.put("comeTotalNum", comNum);
                        object.put("outTotalNum", outNum);
                    }
                }

                list.add(object);

            }
            code = "200";
            msg = "成功";
        } else {
            code = "500";
            msg = "项目名不能为空";
        }
        map.put("data", list);
        //各个摄像头进出总人数数据
        map.put("in_data", list1);
        map.put("out_data", list2);
        map.put("code", code);
        map.put("msg", msg);
        return map;
    }


    /**
     * 实时人数数据
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/number", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Map<String, Object> number() throws Exception {
        String code = "500";
        String msg = "失败";
        List<JSONObject> list = new ArrayList<JSONObject>();
        Map<String, Object> map = new HashMap<String, Object>();
        int comeTotal = 0;
        int outTotal = 0;
        int comeTotalNum = 0;
        int outTotalNum = 0;
        String name = request.getParameter("name");// 项目名称
        String cameraName = request.getParameter("cameraName");//摄像头名称
        if (null != name && !"".equals(name)) {
            // 根据项目名找到项目   max(id)
            CameranotiyExample cameranotiyExample2 = new CameranotiyExample();
            CameranotiyExample.Criteria cameranotiyCiteria2 = cameranotiyExample2.createCriteria();
            cameranotiyCiteria2.andEventNameLike(name);
            if (null != cameraName && !"".equals(cameraName)) {
                cameranotiyCiteria2.andExtstr1EqualTo(cameraName);
            }
            List<Integer> lists = cameranotiyBiz.selectMaxByAll(cameranotiyExample2);
            for (int l : lists) {
                Cameranotiy cameranotiy = cameranotiyBiz.selectByNumber(l);
                comeTotal = cameranotiy.getCometotal();// 进人数
                outTotal = cameranotiy.getOuttotal();// 出人数
//					name = cameranotiy.getExtstr1();
                comeTotalNum = comeTotalNum + comeTotal;
                outTotalNum = outTotalNum + outTotal;
            }

            map.put("comeTotalNum", comeTotalNum);
            map.put("outTotalNum", outTotalNum);
            map.put("onTotalNum", comeTotalNum - outTotalNum);
            code = "200";
            msg = "成功";
        } else {
            code = "500";
            msg = "项目名不能为空";
        }

        map.put("code", code);
        map.put("msg", msg);
        return map;
    }


    /**
     * 各个摄像头实时图片
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/realTimeImg", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Map<String, Object> realTimeImg() throws Exception {
        String code = "500";
        String msg = "失败";
        String base64Img = "";
        Map<String, Object> map = new HashMap<String, Object>();
        List<JSONObject> list = new ArrayList<JSONObject>();
        String name = request.getParameter("name");// 项目名称
        String cameraName = request.getParameter("cameraName");
        if (null != name && !"".equals(name)) {
            CameranotiyExample cameranotiyExample = new CameranotiyExample();
            CameranotiyExample.Criteria cameranotiyCiteria = cameranotiyExample.createCriteria();
            cameranotiyCiteria.andEventNameLike(name);
            cameranotiyCiteria.andExtImg1IsNotNull();//图片不为空
            if (null != cameraName && !"".equals(cameraName)) {
                cameranotiyCiteria.andExtstr1EqualTo(cameraName);
            }
            List<Integer> lists = cameranotiyBiz.selectMaxByAll(cameranotiyExample);
            if (null != lists && lists.size() > 0) {
                for (int l : lists) {
                    JSONObject obj = new JSONObject();
                    Cameranotiy cameranotiy = cameranotiyBiz.selectByPrimaryKey(l);
                    byte[] img = cameranotiy.getExtimg1();

                    obj.put("base64Img", img);
                    obj.put("cameraName", cameranotiy.getExtstr1());
                    obj.put("id", l);
                    list.add(obj);

                }
                map.put("data", list);
                code = "200";
                msg = "成功";
            }
        } else {
            msg = "项目名不能为空";
        }

//		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//		map.put("time", sdf.format(cameranotiy.getCreatetime()));

        map.put("code", code);
        map.put("msg", msg);
        return map;
    }


    /**
     * 摄像头设备信息录入 设备
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/cameraData", method = {RequestMethod.POST})
    @ResponseBody
    public Map<String, Object> data(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String code = "500";
        String msg = "失败";
        Map<String, Object> map = new HashMap<String, Object>();
        int no = 0;

        String cameraName = request.getParameter("cameraName");// 摄像头名称
        String equipmentName = request.getParameter("equipmentName");// 设备名称 具有唯一性，不可重复
        String equipmentType = request.getParameter("equipmentType");// 设备类型
        String installAddress = request.getParameter("installAddress");// 安装地址
        String ipAddress = request.getParameter("ipAddress");// IP地址
        String equipmentNumber = request.getParameter("equipmentNumber");//设备序列号
        Date date = new Date();
        EquipmentExample equipmentExample = new EquipmentExample();
        EquipmentExample.Criteria equipmentCiteria = equipmentExample.createCriteria();
        equipmentCiteria.andExstr1EqualTo(equipmentNumber);
        List<Equipment> equipments = equipmentBiz.selectByExample(equipmentExample);

        EquipmentExample equipmentExample2 = new EquipmentExample();
        EquipmentExample.Criteria equipmentCiteria2 = equipmentExample2.createCriteria();
        equipmentCiteria2.andEquipmentnameEqualTo(equipmentName);
        equipmentCiteria2.andExstr1NotEqualTo(equipmentNumber);
        List<Equipment> equipments2 = equipmentBiz.selectByExample(equipmentExample2);
        if (null != equipments2 && equipments2.size() > 0) {
            code = "500";
            msg = "设备名已存在，请更换设备名";
        } else if (null != equipments && equipments.size() > 0) {
            Equipment equipment = equipments.get(0);
            equipment.setCameraname(cameraName);
            equipment.setEquipmentname(equipmentName);
            equipment.setEquipmenttype(equipmentType);
            equipment.setInstalladdress(installAddress);
            equipment.setIpaddress(ipAddress);
            equipment.setTime1(date);
            no = equipmentBiz.updateByPrimaryKeySelective(equipment);

        } else {
            Equipment equipment = new Equipment();
            equipment.setCameraname(cameraName);
            equipment.setEquipmentname(equipmentName);
            equipment.setEquipmenttype(equipmentType);
            equipment.setInstalladdress(installAddress);
            equipment.setIpaddress(ipAddress);
            equipment.setTime1(date);
            equipment.setExstr1(equipmentNumber);
            no = equipmentBiz.insert(equipment);
        }

        if (1 == no) {
            code = "200";
            msg = "成功";
        }
        map.put("code", code);
        map.put("msg", msg);
        return map;
    }


    /**
     * 多对多数人数设备配置 后台弹窗
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/createMany", method = {RequestMethod.POST})
    @ResponseBody
    public Map<String, Object> createMany(@RequestBody ManyVo manyVo) throws Exception {
        String code = "500";
        String msg = "失败";
        Map<String, Object> map = new HashMap<String, Object>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        String name = manyVo.getName();// 项目名称
        String equipmentname = manyVo.getEquipmentname();// 设备名称
        int no = 0;
        // 通过名称查询项目id xxid
        if (null == name || "".equals(name)) {
            code = "500";
            msg = "项目名称不能为空";
        } else if (null == equipmentname || "".equals(equipmentname)) {
            code = "500";
            msg = "设备名称不能为空";
        } else {
            EventExample eventExample = new EventExample();
            EventExample.Criteria eventCiteria = eventExample.createCriteria();
            eventCiteria.andNameEqualTo(name);
            List<Event> events = eventBiz.selectByExample(eventExample);
            EquipmentExample equipmentExample = new EquipmentExample();
            EquipmentExample.Criteria equipmentCiteria = equipmentExample.createCriteria();
            equipmentCiteria.andEquipmentnameEqualTo(equipmentname);
            List<Equipment> equipments = equipmentBiz.selectByExample(equipmentExample);
            if (null == events || events.size() == 0) {
                code = "500";
                msg = "项目不存在";
            } else if (null == equipments || equipments.size() == 0) {
                code = "500";
                msg = "设备不存在";
            } else {
                int eventId = events.get(0).getId();
                int equipmentId = equipments.get(0).getId();
                ManyExample manyExample = new ManyExample();
                ManyExample.Criteria manyCiteria = manyExample.createCriteria();
                manyCiteria.andXxidEqualTo(eventId);
                manyCiteria.andYyidEqualTo(equipmentId);
                manyCiteria.andTagEqualTo("event_equipment");
                List<Many> manys = manyBiz.selectByExample(manyExample);
                if (null != manys && manys.size() > 0) {
                    code = "500";
                    msg = "该设备已经配置在此项目中";
                } else {
                    Many many = new Many();
                    many.setXxid(eventId);
                    many.setYyid(equipmentId);
                    many.setTag("event_equipment");
                    many.setCreatetime(date);
                    many.setRemark("项目_设备摄像头");
//					many.setExtstr1("0");
                    no = manyBiz.insert(many);
                }
            }
        }
        if (1 == no) {
            code = "200";
            msg = "成功";
        }
        map.put("code", code);
        map.put("msg", msg);
        return map;
    }

    /**
     * vue下拉框项目 设备数据展示
     *  统计设备配置下拉框创建模块
     *
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/dataList")
    public Map<String, Object> data() {
        Map<String, Object> map = new HashMap<String, Object>();
        List<JSONObject> nameList = new ArrayList<JSONObject>();
        List<JSONObject> equipmentnameList = new ArrayList<JSONObject>();
        List<Event> events = eventBiz.selectVagueN();
        for (Event event : events) {
            JSONObject obj = new JSONObject();
            obj.put("name", event.getName());
            nameList.add(obj);
        }

        EquipmentExample equipmentExample = new EquipmentExample();
        List<Equipment> equipments = equipmentBiz.selectByExample(equipmentExample);
        for (Equipment equipment : equipments) {
            JSONObject obj = new JSONObject();
            obj.put("equipmentname", equipment.getEquipmentname());
            equipmentnameList.add(obj);
        }
        map.put("events", nameList);
        map.put("equipments", equipmentnameList);
        return map;
    }


    @GetMapping("/equipmentList")
    public R equipmentList(@RequestParam Map<String, Object> params) {
        PageUtils page = equipmentService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * vue项目 多对多数人数设备表格展示
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/findPageCamera")
    public HttpResult findPageCamera(@RequestBody PageRequest params) {
        System.out.println(params);
        PageResult result = findPage2(params);
        return HttpResult.ok(result);
    }

    private PageResult findPage2(@RequestBody PageRequest pageRequest) {
        EquipmentExample example = new EquipmentExample();
        example.setOrderByClause("equipment_time1 desc");
        PageResult result = equipmentBiz.findPage(pageRequest, example);
        return result;
    }

//
//	/**
//	 * 删除
//	 * @param
//	 * @return
//	 */
//	@PostMapping(value="/del")
//	@ResponseBody
//	public Map<String, Object> del(@RequestBody Many many) {
//		Map<String, Object> map = new HashMap<String, Object>();
//		int no = 0;
//		String code = "500";
//		String msg = "失败";
//		int id = many.getId();
//
//		ManyExample manyExample = new ManyExample();
//		ManyExample.Criteria manyCriteria = manyExample.createCriteria();
//		manyCriteria.andIdEqualTo(id);
//		manyCriteria.andExtstr1EqualTo("0");//状态正常数据
//		List<Many> manys = manyBiz.selectByExample(manyExample);
//		Date createTime = new Date();
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//		if(null!=manys&&manys.size()>0) {
//			many.setExtstr2(sdf.format(createTime));
//			many.setExtstr1("1");
//			no = manyBiz.updateByPrimaryKeySelective(many);
//		}else {
//			msg = "规则不存在";
//		}
//		if(1==no) {
//			code = "200";
//			msg = "成功";
//
//		}
//		map.put("code", code);
//		map.put("msg",msg);
//		return map;
//	}
}
